number = input().strip()
if "0" <= number and number <= "9999" and len(number) == 4:
    n = number
    a = 0
    for i in range(4):
        for j in range(i + 1, 5):
            b = int(n[i:j])
            is_prime = True
            if b < 2:
                is_prime = False
            else:
                c = 2
                while c * c <= b:
                    if b % c == 0:
                        is_prime = False
                        break
                    c += 1
            if is_prime and b > a:
                a = b

    print(a)
else:
    print(0)
